<template>
    <view>
        <!-- pages/setParking2/index.wxml -->
		<view class="head-block" v-if="weixin == 2">
				     <view class="nav-title" :style="'top:10px'"></view>
					 <!-- 返回 -->
					 <view class="icons" @tap="goMy" :style="'top:6px'">
					      <van-icon name="arrow-left" color="#333" size="45rpx" />
					  </view>
				 </view>
        <view class="body">
            <van-cell-group>
                <!-- 包月 -->
                <view v-if="active == 1">
                    <view style="padding: 10rpx 32rpx; display: flex" @tap="showPopupcw">
                        <view style="font-size: 40rpx; margin-right: 20rpx">{{ parkingName }}</view>
                        <view style="display: inline-block" class="card-order-spnum">
                            <text class="spnum-fixtext">车位</text>
                            <text class="spnum-num">{{ parkingNumber }}</text>
                        </view>
                    </view>
                    <van-cell title="共享类型" is-link :value="activeName" @click="showActive" />
                    <van-cell title="起租时间" :value="date ? date : '请选择'" is-link @click="onDisplayby" />
                    <view class="cw-selectDate" style="margin-top: 0rpx; position: relative">
                        <text class="" style="position: absolute; top: 15rpx">包月定价</text>
                        <input
                            placeholder="请输入..."
                            style="
                                width: 210rpx;
                                text-align: center;
                                border: 1rpx solid #000;
                                display: inline-block;
                                margin-left: 368rpx;
                                margin-right: 5rpx;
                                position: relative;
                                top: 12rpx;
                            "
                            v-model="unitPrice"
                        />
                        <text style="position: absolute; top: 15rpx; right: 35rpx">元/月</text>
                    </view>
                    <!-- <van-cell title="包月定价" value="{{price.unitPrice/100 || '--'}}" /> -->
                   <!-- <van-calendar :default-date="caleDate" v-model="showcalendar" @close="onClose" @confirm="onConfirm" /> -->
                    <van-calendar :default-date="caleDateby" v-model="showcalendarby" @close="onCloseby" @confirm="onConfirmby" />
                    <van-cell title="租赁期限" :value="cycle ? cycle : '请选择'" is-link @click="showPopupcycleby" />
                    <van-cell title="共享时间段" value="全天（默认）" />
                    <view class="cw-selectDate">
                        <view class="cw-date-title" style="display: inline-block">车位类型</view>
                        <van-radio-group style="top: -2px; position: absolute; right: 0" v-model="radio3" @change="onChange3" direction="horizontal">
                            <van-radio name="1" checked-color="#00BCAB">地面</van-radio>
                            <van-radio name="2" checked-color="#00BCAB">地下</van-radio>
                        </van-radio-group>
                    </view>
                    <view class="cw-selectDate">
                        <view class="cw-date-title" style="display: inline-block">充电服务</view>
                        <van-radio-group style="top: -2px; position: absolute; right: 0; margin-top: 20rpx" v-model="radio2" @change="onChange2" direction="horizontal">
                            <van-radio name="1" checked-color="#00BCAB">是</van-radio>
                            <van-radio name="2" checked-color="#00BCAB">否</van-radio>
                        </van-radio-group>
                        <view class="elcTip">是否给车主提供充电服务（费用双方协商）</view>
                    </view>
                    <view class="vanTabView" v-if="radio2 == 1">
                        <view :class="'vanTab vanTab1 ' + (carType == 'gj' ? 'active' : '')" data-id="gj" style="margin-right: 20rpx" @tap="changeTab">国标</view>
                        <view :class="'vanTab vanTab2 ' + (carType == 'tsl' ? 'active' : '')" data-id="tsl" @tap="changeTab">特斯拉专用</view>
                    </view>
                </view>
                <view v-else>
                    <view style="padding: 10rpx 32rpx; display: flex" @tap="showPopupcw">
                        <text style="font-size: 40rpx; margin-right: 20rpx">{{ parkingName }}</text>
                        <view style="display: inline-block" class="card-order-spnum">
                            <text class="spnum-fixtext">车位</text>
                            <text class="spnum-num">{{ parkingNumber }}</text>
                        </view>
                    </view>
                    <van-cell title="共享类型" is-link :value="activeName" @click="showActive" />
                    <view class="cw-selectDate">
                        <view class="cw-date-title">起止日期</view>
                        <view class="cw-date-content" @tap="onDisplay">
                            <view class="cw-date-st">{{ stDate }}</view>
                            <view class="cw-date-middle">至</view>
                            <view class="cw-date-st">{{ edDate }}</view>
                        </view>
                    </view>
                    <view class="cw-selectDate">
                        <view class="cw-date-title">当天共享时段</view>
                        <view class="cw-date-content" @tap="showPopuptime">
                            <view class="cw-date-st">{{ startTime || '' }}</view>
                            <view class="cw-date-middle">至</view>
                            <view class="cw-date-st">{{ radio === '1' ? '' : '(次日)' }}{{ endTime ? endTime : '' }}</view>
                        </view>
                    </view>

                    <!-- <van-cell title="选择日期区间" value="{{ date?date:'请选择' }}" is-link bind:click="onDisplay" /> -->
                    <van-calendar v-if="showcalendar"  v-model="showcalendar" type="range" @close="onClose" @confirm="onConfirm" />
                    <view class="Tips">温馨提示：车位的共享时间不可短于6小时</view>
                    <van-cell title="重复周期" :value="selectCycName ? selectCycName : '请选择'" is-link @click="showPopupcycle" />
                    <view class="cw-selectDate" style="margin-top: 0rpx; position: relative">
                        <text style="position: absolute; top: 15rpx">临停定价</text>
                        <input
                            placeholder="请输入..."
                            style="
                                width: 210rpx;
                                text-align: center;
                                border: 1rpx solid #000;
                                display: inline-block;
                                margin-left: 368rpx;
                                margin-right: 5rpx;
                                position: relative;
                                top: 12rpx;
                            "
                            v-model="unitPrice"
                        />
                        <text style="position: absolute; top: 15rpx; right: 35rpx">元/次</text>
                    </view>
                    <view class="cw-selectDate">
                        <view class="cw-date-title" style="display: inline-block">车位类型</view>
                        <van-radio-group style="top: -2px; position: absolute; right: 0" v-model="radio3" @change="onChange3" direction="horizontal">
                            <van-radio name="1" checked-color="#00BCAB">地面</van-radio>
                            <van-radio name="2" checked-color="#00BCAB">地下</van-radio>
                        </van-radio-group>
                    </view>
                    <view class="cw-selectDate">
                        <view class="cw-date-title" style="display: inline-block">充电服务</view>
                        <van-radio-group style="top: -2px; position: absolute; right: 0; margin-top: 20rpx" v-model="radio2" @change="onChange2" direction="horizontal">
                            <van-radio name="1" checked-color="#00BCAB">是</van-radio>
                            <van-radio name="2" checked-color="#00BCAB">否</van-radio>
                        </van-radio-group>
                        <view class="elcTip">是否给车主提供充电服务（费用双方协商）</view>
                    </view>
                    <view class="vanTabView" v-if="radio2 == 1">
                        <view :class="'vanTab vanTab1 ' + (carType == 'gj' ? 'active' : '')" data-id="gj" style="margin-right: 20rpx" @tap="changeTab">国标</view>
                        <view :class="'vanTab vanTab2 ' + (carType == 'tsl' ? 'active' : '')" data-id="tsl" @tap="changeTab">特斯拉专用</view>
                    </view>
                </view>
            </van-cell-group>
            <view class="rules">
                <view class="rules-title">使用须知：</view>
                <view class="rules-content" v-if="active == 1">
                    <view>1、请在收到预约订单后2日内联系物业录入车牌、确认订单履约。</view>
                    <view>2、如遇到超时停车、提前结束共享等异常情况，请业主跟预 约车主双方直接协商。</view>
                    <view>3、订单生效7日后收益计入您的钱包余额。</view>
                </view>

                <view class="rules-content" v-else>
                    <view>1、临停租用以次数形式计费。车主购买次数后，可在预约日期当天共享时段内无限次出入。</view>
                    <view>2、如遇到超时停车、提前结束共享等异常情况，请业主跟预约车主双方直接协商。</view>
                    <view>3、订单生效7日后收益计入您的钱包余额。</view>
                </view>
            </view>
            <view class="rule">
                <van-checkbox v-model="checked" @change="onChangeCheckbox" checked-color="#00BCAB"></van-checkbox>
                <text @tap="showRule" style="padding-left: 10rpx">我已经阅读并同意《邻里车位合作协议》</text>
            </view>
            <view class="agree-btn">
                <van-button type="info" @tap.native="goOk">确定发布</van-button>
            </view>
            <!-- 车位弹窗 -->
            <van-popup v-model="showcw" position="bottom" @close="onClosecw">
                <van-picker show-toolbar :columns="columnscw" @cancel="onCancelcw" @confirm="onConfirmcw" @change="onChangecw" />
            </van-popup>
            <!-- 类型弹窗 -->
            <van-popup v-model="showactive" position="bottom" @close="onCloseactive">
                <van-picker show-toolbar :columns="columnsactive" :default-index="active" @cancel="onCancelactive" @confirm="onConfirmactive"  />
            </van-popup>
            <!-- 时间 -->
            <van-popup v-model="show" position="bottom" custom-style="height: 50%;" @close="onCloseTime">
                <div v-if="chooseStart">
                    <text class="startTitle">选择开始时间</text>
                    <van-datetime-picker
                        id="startTimePicker"
                        type="time"
                        v-model="currentDate"
						:filter=" filter "
                        @change="onInput($event, { tagId: 'startTimePicker' })"
                        @confirm="startTimeConfirm($event, { tagId: 'startTimePicker' })"
                        @cancel="onCancelstartTime($event, { tagId: 'startTimePicker' })"
                    />
                </div>
                <div v-else>
                    <text class="startTitle">选择结束时间</text>
                    <view v-if="radio === '1'">
                        <van-datetime-picker
						:filter=" filter "
                            type="time"
                            v-model="currentDate"
                            :min-hour="minHour"
                           
                            @change="onInput"
                            @confirm="endTimeConfirm"
                            @cancel="onCancelendTime"
                        />
                    </view>
                    <view v-if="radio == '2'">
                        <van-datetime-picker :filter=" filter " type="time" v-model="currentDate" :min-minute="minMinute" @change="onInput" @confirm="endTimeConfirm" @cancel="onCancelendTime" />
                    </view>
                </div>
            </van-popup>
            <!-- 重复周期 -->
            <van-popup v-model="showcycle" close-icon="close" position="bottom" @close="onClosecycle">
                <van-checkbox-group v-model="selectCyc">
                    <van-cell-group>
                        <van-cell value-class="value-class" title="每天" clickable data-name="每天" @click="selectAll($event, { name: '每天' })">
                            <van-checkbox name="每天" />
                        </van-cell>
                        <van-cell
                            value-class="value-class"
                            :title="item.name"
                            clickable
                            :data-name="item.name"
                            @click="toggle($event, { name: item.name })"
                            v-for="(item, index) in cyclelist"
                            :key="index"
                        >
                            <van-checkbox :class="'checkboxes-' + index" :name="item.name" />
                        </van-cell>
                        <van-cell value-class="value-class" title="不重复" clickable data-name="不重复" @click="noSelect($event, { name: '不重复' })">
                            <van-checkbox name="不重复" />
                        </van-cell>
                    </van-cell-group>
                </van-checkbox-group>
                <!-- <van-picker show-toolbar title="选择周期" columns="{{ columns }}" bind:cancel="onCancelcycle" bind:confirm="onConfirmcycle" bind:change="onChangecycle" /> -->
            </van-popup>
            <!-- 重复周期 -->
            <van-popup v-model="showcycleby" close-icon="close" position="bottom" @close="onClosecycleby">
                <van-picker show-toolbar title="选择周期" :columns="columnsby" @cancel="onCancelby" @confirm="onConfirmcycleby" />
            </van-popup>
        </view>
        <van-dialog id="van-dialog" confirm-button-text="我知道了" confirm-button-color="#00BCAB" />
        <van-dialog
            use-slot
            title="修改车位号"
            confirm-button-color="#00BCAB"
            v-model="showparkingNumber"
            show-cancel-button
            confirm-button-open-type="getUserInfo"
            @close="onCloseparkingNumber"
            @getuserinfo="getUserInfoparkingNumber"
        >
            <view style="padding-left: 30rpx">当前关联车号 {{ parkingNumber }}</view>
            <van-field v-model="parkingNumberValue" label="申请修改为" type="textarea" autosize :border="false" @change="changeValue" />
            <view class="Tips">温馨提示：提交修改后，由物业审核，请耐心等待。详询物业中心。</view>
        </van-dialog>
        <view class="rule-pop">
            <van-popup round v-model="showRulePop" @close="closeRule">
                <view class="rules">
                    <view class="rule-title">邻里车位合作协议</view>
                    <!-- <view class="rule-content">
        {{platformRules}}
      </view> -->
                    <view class="rule-content">
                        <rich-text :nodes="platformRules"></rich-text>
                    </view>
                    <view class="rule-line"></view>
                    <view class="rule-know" @tap="closeRule">我知道了</view>
                </view>
            </van-popup>
        </view>
    </view>
</template>

<script>
// pages/setParking2/index.js
import util from './../../utils/util.js';
import api from './../../utils/api.js';
import { Dialog } from 'vant';
import config from './../../utils/config.js'; // import moment from "moment";

export default {
    data() {
        return {
			filter(type, options) {
			      if (type === 'minute') {
			        return options.filter((option) => option % 30 === 0);
			      }
			
			      return options;
			    },
            unitPrice: '',
            carType: 'gj',
            radio2: '2',
            radio3: '1',

            columnsby: [
                {
                    text: '1个月',
                    index: 1
                },
                {
                    text: '2个月',
                    index: 2
                },
                {
                    text: '3个月',
                    index: 3
                },
                {
                    text: '4个月',
                    index: 4
                },
                {
                    text: '5个月',
                    index: 5
                },
                {
                    text: '6个月',
                    index: 6
                },
                {
                    text: '7个月',
                    index: 7
                },
                {
                    text: '8个月',
                    index: 8
                },
                {
                    text: '9个月',
                    index: 9
                },
                {
                    text: '10个月',
                    index: 10
                },
                {
                    text: '11个月',
                    index: 11
                },
                {
                    text: '12个月',
                    index: 12
                }
            ],

            maxDate: new Date(new Date().getTime() + 24 * 60 * 60 * 1000 * 365),
            activeName: '临停',
            active: 0,

            //0--临时，1--月，2--新的
            parkingName: '',

            //停车场名字
            parkingNumber: '',

            //停车场名字
            parkingCode: '',

            //停车场编码
            showcw: false,

            //车位
            showactive: false,

            //类型
            date: '',

            //日期
            showcalendar: false,

            show: false,
            chooseStart: true,

            //表示在选择开始时间还是结束时间true是开始时间
            currentDate: '12:00',

            minHour: 0,
            minMinute: 0,
            radio: '1',
            startTime: null,
            endTime: null,
            cycle: null,

            //周期
            cycleValue: null,

            //周期id
            showcycle: false,

            // unionId: wx.getStorageSync("unionId") || "",
            // unionId: "fb0feca5-0945-4989-b4aa-8c33413ff648",
            cyclelist: [
                {
                    name: '星期一',
                    value: 0,
                    disabled: false
                },
                {
                    name: '星期二',
                    value: 0,
                    disabled: false
                },
                {
                    name: '星期三',
                    value: 0,
                    disabled: false
                },
                {
                    name: '星期四',
                    value: 0,
                    disabled: false
                },
                {
                    name: '星期五',
                    value: 0,
                    disabled: false
                },
                {
                    name: '星期六',
                    value: 0,
                    disabled: false
                },
                {
                    name: '星期日',
                    value: 0,
                    disabled: false
                }
            ],

            selectCyc: ['不重复'],
            selectCycName: '不重复',
            columnscw: [],

            columnsactive: [
                {
                    name: '临停',
                    value: 0,
                    text: '临停'
                },
                {
                    name: '包月',
                    value: 1,
                    text: '包月'
                }
            ],

            checked: false,
            showcw: false,
            id: null,
            caleDate: [],
            showparkingNumber: false,
            parkingNumberValue: '',
            stDate: '',
            edDate: '',
            price: {},
            platformRules: config.platformRulesLlgx,
            showRulePop: false,
            showcalendarby: false,
            showcycleby: false,
            cycleindex: '',
            editData: '',
            manage: '',
            caleDateby: '',
			weixin:uni.getStorageSync('weixin')
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
        if (options.active) {
            this.setData({
                active: parseInt(options.active)
            });
        }

        if (this.active == 1) {
            this.setData({
                activeName: '包月'
            });
        } else {
            this.setData({
                activeName: '临停'
            });
        }

        if (options.id) {
            this.setData(
                {
                    id: options.id
                }
            );
			this.getmySpaceList();
        } else {
            this.getmySpaceList();
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    // onShareAppMessage: function () {}
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */ methods: {
        changeTab: function (e) {
            console.log(e.currentTarget.dataset.id);
            this.setData({
                carType: e.currentTarget.dataset.id
            });
        },

        onChange2(event) {
            this.setData({
                radio2: event
            });
        },

        onChange3(event) {
            this.setData({
                radio3: event
            });
        },

        onCloseparkingNumber() {
            this.setData({
                showparkingNumber: false
            });
        },

        getUserInfoparkingNumber() {
            this.setData({
                showparkingNumber: false
            });
            this.setspaceModify();
        },

        changeparkingNumber() {
            this.setData({
                showparkingNumber: true,
                parkingNumberValue: ''
            });
        },

        changeValue(e) {
            this.setData({
                parkingNumberValue: e
            });
        },

        showPopupcw() {
            this.setData({
                showcw: true //车位
            });
        },

        showActive() {
            this.setData({
                showactive: true //类型
            });
        },

        onDisplay() {
            this.setData({
                showcalendar: true
            });
        },

        onClose() {
            this.setData({
                showcalendar: false
            });
        },
		goMy() {
		     uni.navigateBack({
		         delta: 1
		     });
		 },
        formatDate(date) {
            var Dates = new Date(date);
            var Y = Dates.getFullYear();
            var M = Dates.getMonth() + 1;
            var D = Dates.getDate();
            var times = Y + (M < 10 ? '/0' : '/') + M + (D < 10 ? '/0' : '/') + D; // return `${date.getFullYear() / date.getMonth() + 1}/${date.getDate()}`;

            return times;
        },

        onConfirm(event) {
			console.log(event);
            const [start, end] = event;
            this.setData({
                showcalendar: false,
                date: `${this.formatDate(start)} - ${this.formatDate(end)}`,
                stDate: this.formatDate(start),
                edDate: this.formatDate(end)
            });
        },

        showPopuptime() {
            this.setData({
                show: true
            });
        },

        onClosetime() {
            // this.setData({ show: false });
        },

        //选择周期
        showPopupcycle() {
            this.setData({
                showcycle: true
            });
        },

        //时间
        onDisplayby() {
            this.setData({
                showcalendarby: true
            });
        },

        onCloseby() {
            this.setData({
                showcalendarby: false
            });
        },

        onConfirmby(event) {
            const start = event;
            console.log(start);

            if (start && start.length != 0) {
                this.setData({
                    showcalendarby: false,
                    date: `${this.formatDate(start)}`
                });
            } else {
                this.setData({
                    showcalendarby: false
                });
            }
        },

        onConfirmcycleby(event,value) {
			console.log(event)
            // const { picker, value, index } = event;
            this.setData({
                showcycleby: false,
                cycle: event.text,
                cycleindex: event.index
            }); // Toast(`当前值：${value}, 当前索引：${index}`);
        },

        onClosecycle() {
            this.setData({
                showcycle: false
            });
        },

        //选择包月租赁
        showPopupcycleby() {
            this.setData({
                showcycleby: true
            });
        },

        onClosecycleby() {
            this.setData({
                showcycleby: false
            });
        },

        onChange(event) {
            // this.setData({
            //   result: event
            // });
        },

        onChangeChoice(e) {
            const selectCyc = e;
            const { cyclelist } = this;

            if (selectCyc.indexOf('每天')) {
                cyclelist.forEach((e) => {
                    if (e.name == '不重复') {
                        e.value = 0;
                    } else {
                        e.value = 1;
                        e.disabled = true;
                    }
                });
            } else if (selectCyc.indexOf('不重复')) {
                cyclelist.forEach((e) => {
                    if (e.name == '不重复') {
                        e.value = 1;
                    } else {
                        e.value = 0;
                        e.disabled = true;
                    }
                });
            } else {
                cyclelist.forEach((e) => {
                    if (selectCyc.indexOf(e.name) >= 0) {
                        e.value = 1;
                    } else {
                        e.value = 0;
                    }
                });
            }

            let newSelectCyc = cyclelist.filter((e) => e.value).map((e) => e.name);
            this.setData(
                {
                    selectCyc: newSelectCyc
                },
                () => {
                    this.setData({
                        selectCycName: cyclelist.filter((e) => e.value).map((e) => e.name)
                    });
                }
            );
        },

        selectAll(e, _dataset) {
            /* ---处理dataset begin--- */
            
            /* ---处理dataset end--- */
            let { cyclelist } = this;

            if (this.selectCyc.indexOf('每天') >= 0) {
                this.noSelect();
                return;
            }

            cyclelist.forEach((e) => {
                e.value = 1;
            });
            let selectCyc = cyclelist.filter((e) => e.value).map((e) => e.name);
            selectCyc.push('每天');
            this.setData({
                selectCyc,
                cyclelist,
                selectCycName: '每天'
            });
        },

        noSelect(e, _dataset) {
            /* ---处理dataset begin--- */
            
            /* ---处理dataset end--- */
            let selectCyc = ['不重复'];
            let { cyclelist } = this;
            cyclelist.forEach((e) => {
                e.value = 0;
            });
            this.setData({
                selectCyc,
                cyclelist,
                selectCycName: '不重复'
            });
        },

        toggle(event, _dataset) {
            /* ---处理dataset begin--- */
            // this.datasetHandle(event, _dataset);
            /* ---处理dataset end--- */
            const name = event.currentTarget.dataset.name;
            this.toggleMy(name, false);
        },

        toggleMy(name, isReload) {
            let { cyclelist, selectCyc } = this; // if (!isReload) {

            cyclelist.forEach((e) => {
                if (e.name == name) {
                    if (e.value) {
                        e.value = 0;
                    } else {
                        e.value = 1;
                    }
                }
            }); // }

            selectCyc = cyclelist.filter((e) => e.value).map((e) => e.name);
            let selectCycName = selectCyc
                .map((e, i) => {
                    if (i !== selectCyc.length - 1) {
                        return e.split('')[2] + '、';
                    } else {
                        return e.split('')[2];
                    }
                })
                .join('');
            this.setData({
                cyclelist,
                selectCyc,
                selectCycName: `星期${selectCycName}`
            });
            let a = cyclelist.filter((e) => e.value);

            if (a.length == 7) {
                this.selectAll();
            } else if (a.length == 0) {
                this.noSelect();
            }
        },

        noop() {},

        onConfirmcycle(event) {
            // const { picker, value, index } = event;
            this.setData({
                showcycle: false
            }); // Toast(`当前值：${value}, 当前索引：${index}`);
        },

        onChangecycle(e) {
            console.log(e, 'aaa');
            this.setData({
                cycle: e.value.text,
                cycleValue: e.value.value
            });
        },

        onCancelcycle() {
            this.setData({
                showcycle: false
            }); // Toast('取消');
        },

        //车位号
        onClosecw() {
            this.setData({
                showcw: false //车位
            });
        },

        //类型
        onCloseactive() {
            this.setData({
                showactive: false
            });
        },

        onCancelcw() {
            this.setData({
                showcw: false //车位
            });
        },

        onCancelactive() {
            this.setData({
                showactive: false
            });
        },

        onConfirmcw(e) {
            this.setData({
                showcw: false
            });
        },

        onConfirmactive(e,value,index) {
			console.log(value);
			this.active=value;
			this.showactive=false;
			this.activeName=e.name;
			// this.setData({
			//     activeName:value.name ,
			//     active: index,
			//     date: ''
			// });

            if (this.active == 0) {
                // this.reLoadData()
                this.getProducts();
            } else {
                // this.reLoadDataBy()
                this.getProductsby();
				this.date = ""
            }
        },

        onChangeactive(picker, value, index) {
            console.log(value.name);
			this.active=index
			this.activeName=value.name
            // this.setData({
            //     activeName:value.name ,
            //     active: index,
            //     date: ''
            // });
			// this.$forceUpdate()
            if (this.active == 0) {
                this.reLoadData();
                this.getProducts();
            } else {
                this.reLoadDataBy();
                this.getProductsby();
            }
        },

        onChangecw(e) {
            this.setData({
                parkingNumber: e.value.parkingNumber,
                parkingName: e.value.parkingName,
                parkingCode: e.value.parkingCode
            });

            if (this.active == 0) {
                this.getProducts();
            } else {
                this.getProductsby();
            }
        },

        // onInput(event) {
        //   this.setData({
        //     currentDate: event
        //   });
        // },
        // 点击选择开始时间的确定按钮
        onCloseTime() {
            this.setData({
                show: false
            });
        },

        startTimeConfirm(e, _dataset) {
            /* ---处理dataset begin--- */
            // 
            /* ---处理dataset end--- */
            let minHour = 0;
            let minMinute = 0;

            if (this.radio == '1') {
                minHour = +e.split(':')[0] + 6;
                minMinute = +e.split(':')[1] + 1;
                console.log(minHour + ':' + minMinute);
            } else {
                minHour = 23;
                minMinute = 59;
            }

            if (minHour >= 24) {
				minHour = 23;
				minMinute = 59;
                // this.setData({
                //     radio: '2'
                // });
                // minHour = 0;
            }

            this.setData({
                chooseStart: false,
                show: true,
                startTime: e,
                minHour,
                minMinute
            });
        },

        endTimeConfirm(e) {
            this.setData({
                chooseStart: true,
                show: false,
                endTime: e
            });
        },

        onChange(event) {
            const radio = event.value;
            let minHour = 0;
            let minMinute = 0;

            if (radio == '1') {
                minHour = +this.startTime.split(':')[0];
                minMinute = +this.startTime.split(':')[1];
            } else {
                // console.log(1111)
                if (this.startTime.split(':')[1] - 1 == -1) {
                    minHour = +this.startTime.split(':')[0] - 1;
                    minMinute = 59;
                } else {
                    minHour = +this.startTime.split(':')[0];
                    minMinute = +this.startTime.split(':')[1] - 1;
                }
            }

            this.setData({
                radio,
                minHour,
                minMinute
            });
        },

        onInput(e, _dataset) {
            /* ---处理dataset begin--- */
            // 
            /* ---处理dataset end--- */
            // console.log(e.getValues())
            let time = e.getValues();

            if (!this.startTime) {
                this.setData({
                    currentDate: time[0] + ':' + time[1]
                });
                return;
            }

            if (this.radio == '1' && +time[0] == +this.startTime.split(':')[0]) {
                this.setData({
                    minMinute: +this.startTime.split(':')[1] + 1,
                    currentDate: time[0] + ':' + time[1]
                });
            } else {
                this.setData({
                    minMinute: 0,
                    currentDate: time[0] + ':' + time[1]
                });
            }
        },

        onCancelstartTime(e, _dataset) {
            /* ---处理dataset begin--- */
            
            /* ---处理dataset end--- */
            this.setData({
                show: false,
                startTime: null,
                endTime: null
            });
        },

        onCancelendTime() {
            this.setData({
                chooseStart: true,
                endTime: null
            });
        },

        //发布车位
        setparkingReleaseby() {
            console.log('setparkingRelease');
            var validStartTime = this.date.replaceAll('/', '-');
            var enddatemonth = +this.date.split('/')[1] + +this.cycleindex;
            var enddateyear = +this.date.split('/')[0].toString();

            if (enddatemonth < 10) {
                enddatemonth = '0' + enddatemonth;
            } else if (enddatemonth > 12) {
                enddateyear = +this.date.split('/')[0].toString() + 1;
                enddatemonth = enddatemonth - 12;
            }

            const endDataTime = enddateyear + '-' + enddatemonth + '-' + +this.date.split('/')[2];
            const unionId = uni.getStorageSync('unionId') || '';

            if ((!this.unitPrice && this.unitPrice != 0) || parseFloat(this.unitPrice) <= 0 || isNaN(parseInt(this.unitPrice))) {
                uni.showToast({
                    title: '定价金额需大于0元',
                    icon: 'none'
                });
                return;
            }

            const param = {
                userUnionId: unionId,
                spaceNo: this.parkingNumber,
                parkingCode: this.parkingCode,
                type: 2,
                //1临停预约，2包整月，3夜间包月
                validStartTime: validStartTime + ' ' + '00:00:00',
                validEndTime: endDataTime + ' ' + '00:00:00',
                haveCharge: this.radio2 == 1 ? '1' : '0',
                unitPrice: this.unitPrice ? this.unitPrice * 100 : '0',
                spaceType: this.radio3,
                // chargeStandard:this.data.carType=='gj'?'1':'2',
                tempCycle: this.tempCycle
            };

            if (this.radio2 == 1) {
                if (this.carType == 'gj') {
                    param.chargeStandard = '1';
                } else {
                    param.chargeStandard = '2';
                }
            } else {
                param.chargeStandard = '';
            }

            console.log(this.checked);

            if (!validStartTime) {
                uni.showToast({
                    title: '请输入日期',
                    icon: 'none'
                });
                return;
            } else if (!this.cycle) {
                uni.showToast({
                    title: '请输入租赁期限',
                    icon: 'none'
                });
                return;
            } else if (!this.checked) {
                Dialog.alert({
                    message: '请阅读并同意《邻里车位合作协议》'
                }).then(() => {
                    // on close
                });
                return;
            }

            if (this.checked) {
                util.request(api.parkingRelease, param, 'POST').then((res) => {
                    if (res.code == 0) {
                        this.getchangeSaleStatus(); //发布成功直接上架
                    } else {
                        uni.showToast({
                            title: res.msg,
                            icon: 'none'
                        });
                    }
                });
            }
        },

        //我已经阅读并同意《邻里车位合作协议》
        onChangeCheckbox(event) {
            this.setData({
                checked: event
            });
        },

        goOk() {
            if (this.active == 1) {
                this.setparkingReleaseby();
            } else {
                this.setparkingRelease();
            }
        },

        //修改车位
        setspaceModify() {
            const unionId = uni.getStorageSync('unionId') || '';
            util.request(
                api.spaceModify +
                    '?userUnionId=' +
                    unionId +
                    '&parkingCode=' +
                    this.parkingCode +
                    '&parkingNumber=' +
                    this.parkingNumberValue +
                    '&oldParkingNumber=' +
                    this.parkingNumber,
                'get'
            ).then((res) => {
                if (res.success == true) {
                    uni.showToast({
                        title: res.data,
                        icon: 'none'
                    });
                } else {
                    uni.showToast({
                        title: res.msg,
                        icon: 'none'
                    });
                }
            });
        },

        //我的车位
        getmySpaceList() {
            const unionId = uni.getStorageSync('unionId') || '';
            util.request(api.mySpaceList + '?userUnionId=' + unionId, 'get').then((res) => {
                if (res.code == 0) {
                    var array = [];

                    if (res.data) {
                        res.data.map((e, index) => {
                            if (e.authStatus == 1) {
                                //只展示审核通过的
                                array.push(
                                    Object.assign({}, e, {
                                        text: e.parkingNumber
                                    })
                                );
                            }
                        });
                    }

                    this.setData({
                        columnscw: array,
                        //车位
                        parkingNumber: array.length && this.id ? array.find((e) => e.id == this.id).parkingNumber : '',
                        parkingName: array.length && this.id ? array.find((e) => e.id == this.id).parkingName : '',
                        parkingCode: array.length && this.id ? array.find((e) => e.id == this.id).parkingCode : '',
                        editData: this.id && array.length ? array.find((e) => e.id == this.id).plmParkingSpaceManage : {}
                    });

                    if (this.active == 0) {
                        this.reLoadData();
                        this.getProducts();
                    } else {
                        this.reLoadDataBy();
                        this.getProductsby();
                    }
                }
            });
        },

        //  回写数据
        reLoadDataBy() {
            const { id, editData } = this;

            if (!editData) {
                return;
            } // let cyclelist = JSON.parse(JSON.stringify(this.data.cyclelist));

            if (id) {
                const { validStartTime, validEndTime, tempStartTime, tempEndTime, tempCycle } = editData; // 整理日期

                const date = validStartTime ? validStartTime.split(' ')[0].replaceAll('-', '/') : '';
                let startm = validStartTime ? validStartTime.split(' ')[0].split('-')[1] : '';
                let endm = validStartTime ? validEndTime.split(' ')[0].split('-')[1] : '';
                const cycleindex = endm - startm;
                const cycle = this.columnsby.find((e) => e.index == cycleindex) ? this.columnsby.find((e) => e.index == cycleindex).text : '';
                console.log(cycleindex);
                this.setData({
                    date,
                    caleDate: validStartTime ? validStartTime.split(' ')[0] : '',
                    cycleindex,
                    cycle
                });
            }
        },

        //发布车位
        setparkingRelease() {
            var validStartTime = null;
            var validEndTime = null;

            if (this.date) {
                validStartTime = this.date.split('-')[0].replaceAll('/', '-');
                validEndTime = this.date.split('-')[1].replaceAll('/', '-').concat(' ');
            }

            const tempCycle = this.cyclelist.map((e) => e.value).join('');
            const unionId = uni.getStorageSync('unionId') || '';

            if ((!this.unitPrice && this.unitPrice != 0) || parseFloat(this.unitPrice) <= 0 || isNaN(parseInt(this.unitPrice))) {
                uni.showToast({
                    title: '定价金额需大于0元',
                    icon: 'none'
                });
                return;
            }

            const param = {
                userUnionId: unionId,
                spaceNo: this.parkingNumber,
                parkingCode: this.parkingCode,
                type: 1,
                //1临停预约，2包整月，3夜间包月
                validStartTime: validStartTime + '00:00:00',
                validEndTime: validEndTime + '00:00:00',
                tempCycle: tempCycle,
                tempStartTime: this.startTime + ':00',
                tempEndTime: this.endTime + ':00',
                tempCrossDay: this.radio == 1 ? 0 : 1,
                //次日
                haveCharge: this.radio2 == 1 ? '1' : '0',
                spaceType: this.radio3,
                unitPrice: this.unitPrice ? this.unitPrice * 100 : '0'
            };

            if (!validStartTime) {
                uni.showToast({
                    title: '请输入起止日期',
                    icon: 'none'
                });
                return;
            } else if (!validEndTime) {
                uni.showToast({
                    title: '请输入起止日期',
                    icon: 'none'
                });
                return;
            } else if (!this.startTime) {
                uni.showToast({
                    title: '请输入当天共享时段',
                    icon: 'none'
                });
                return;
            } else if (!this.endTime) {
                uni.showToast({
                    title: '请输入当天共享时段',
                    icon: 'none'
                });
                return;
            } else if (!this.checked) {
                Dialog.alert({
                    message: '请阅读并同意《邻里车位合作协议》'
                }).then(() => {
                    // on close
                });
            }

            if (this.checked) {
                util.request(api.parkingRelease, param, 'POST').then((res) => {
                    if (res.success == true) {
                        this.getchangeSaleStatus(); //发布成功的直接上架
                        // wx.navigateTo({
                        //   url: "../setParkingsuccess/index"
                        // });
                    } else {
                        uni.showToast({
                            title: res.msg,
                            icon: 'none'
                        });
                    }
                });
            }
        },

        //  回写数据
        reLoadData() {
            const { id, editData } = this;
            let cyclelist = JSON.parse(JSON.stringify(this.cyclelist));

            if (id) {
                const { validStartTime, validEndTime, tempStartTime, tempEndTime, tempCycle } = editData; // 整理日期

                if (tempStartTime && tempEndTime) {
                    var date = validStartTime.split(' ')[0].replaceAll('-', '/') + ' - ' + validEndTime.split(' ')[0].replaceAll('-', '/');
                } // 起止时间

                if (tempStartTime) {
                    var startTime = tempStartTime.split(':')[0] + ':' + tempStartTime.split(':')[1];
                }

                if (tempEndTime) {
                    var endTime = tempEndTime.split(':')[0] + ':' + tempEndTime.split(':')[1];
                }

                const currentDate = tempStartTime; // 是否为次日

                let radio;

                if (tempEndTime.split(':')[0] <= tempStartTime.split(':')[0]) {
                    radio = '2';
                } else {
                    radio = '1';
                }

                tempCycle.split('').map((e, i) => {
                    if (+e) {
                        cyclelist[i].value = 1;
                    }
                });
                cyclelist
                    .filter((e) => e.value)
                    .forEach((e) => {
                        this.toggleMy(e.name, true);
                    });
                console.log(this.cyclelist);
                this.setData({
                    date,
                    caleDate: [validStartTime.split(' ')[0], validEndTime.split(' ')[0]],
                    startTime,
                    currentDate,
                    endTime,
                    radio,
                    stDate: validStartTime.split(' ')[0].replaceAll('-', '/'),
                    edDate: validEndTime.split(' ')[0].replaceAll('-', '/')
                });
            }
        },

        //根据停车场编码获取车场产品的价格、免费时长--用于定价规则
        getProductsby() {
            let param = {
                parkingCode: this.parkingCode,
                type: 2,
                spaceNo: this.parkingNumber ? this.parkingNumber : ''
            };
            util.request(api.findProductList, param, 'GET').then((res) => {
                if (res.success) {
                    let list = res.data.productList;
                    if (res.data.manage) {
                        this.setData({
                            manage: res.data.manage,
                            unitPrice: res.data.manage.unitPrice / 100,
                            radio2: res.data.manage.haveCharge ? '1' : '2',
                            radio3: res.data.manage.spaceType + ''
                        });
                    }
					
					if(list){
						list.map((item) => {
							if (item.type == 1) {
								this.setData({
									price: item
								});
							}
						});	
					}

                }
            });
        },

        //根据停车场编码获取车场产品的价格、免费时长--用于定价规则
        getProducts() {
            let param = {
                parkingCode: this.parkingCode,
                type: 1,
                spaceNo: this.parkingNumber ? this.parkingNumber : ''
            };
            util.request(api.findProductList, param, 'GET').then((res) => {
                if (res.success) {
                    let list = res.data.productList;

                    if (res.data.manage) {
                        this.setData({
                            manage: res.data.manage,
                            unitPrice: res.data.manage.unitPrice / 100,
                            radio2: res.data.manage.haveCharge ? '1' : '2',
                            radio3: res.data.manage.spaceType + ''
                        });
                    }

                    list.map((item) => {
                        if (item.type == 3) {
                            this.setData({
                                price: item
                            });
                        }
                    });
                }
            });
        },

        //选择停车场
        showSpaceNamepop() {},

        //展示规则
        showRule() {
            this.setData({
                showRulePop: true
            });
        },

        /**
         * 关闭规则
         */
        closeRule() {
            this.setData({
                showRulePop: false,
                checked: true
            });
        },

        //上架接口
        getchangeSaleStatus() {
            const unionId = uni.getStorageSync('unionId') || '';
            const param = {
                userUnionId: unionId,
                spaceNo: this.parkingNumber,
                parkingCode: this.parkingCode,
                saleStatus: 1
            };
            util.request(api.changeSaleStatus, param, 'POST')
                .then((res) => {
                    if (res.code == 0) {
                        // wx.showToast({ title: res.data, icon: "none" });
                        uni.navigateTo({
                            url: '../setParkingsuccess/index'
                        });
                    } else {
                        uni.showToast({
                            title: res.msg,
                            icon: 'none'
                        });
                    }
                })
                .catch((err) => {
                    uni.showToast({
                        title: '请求异常，请重试',
                        icon: 'none'
                    });
                });
        },

        onCancelby() {
            console.log('占位：函数 onCancelby 未声明');
        }
    }
};
</script>
<style>
@import './index.css';
</style>
